package com.shaoshaohuo.app.view.wxstyle;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap.Config;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;

public class NoScrollGridAdapter extends BaseAdapter {

	/** 上下文 */
	private Context ctx;
	/** 图片Url集合 */
	private ArrayList<String> imageUrls;
	private LayoutInflater inflater=null;  
	public NoScrollGridAdapter(Context ctx, ArrayList<String> urls) {
		this.ctx = ctx;
		this.imageUrls = urls;
		inflater=LayoutInflater.from(ctx);  
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return imageUrls == null ? 0 : imageUrls.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return imageUrls.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageTag iTag = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_gridview, null);
			ImageView imageView = (ImageView) convertView.findViewById(R.id.iv_image);
			iTag = new ImageTag(imageView);
			convertView.setTag(iTag);
		} else {
			iTag = (ImageTag) convertView.getTag();
		}
		DisplayImageOptions options = new DisplayImageOptions.Builder()//
				.cacheInMemory(true)//
				.cacheOnDisk(true)//
				.bitmapConfig(Config.RGB_565)//
				.build();
		ImageLoader.getInstance().displayImage(imageUrls.get(position),
				iTag.im, options);
		return convertView;
	}

	class ImageTag {
		protected ImageView im;
		public ImageTag(ImageView im) {
			this.im = im;
		}
	}
}
